package com.feihao.zhou.mapper;

import com.feihao.zhou.bean.Student;
import com.feihao.zhou.bean.Student_Course;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ManyToMany {

    //多对多查询：
    @Select("select * from student ,stu_cr where student.id=stu_cr.sid group by student.name")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age"),
            @Result(column = "cid", property = "cid"),

            @Result(
                    property = "course", javaType = List.class,
                    column = "id",
                    many = @Many(select = "com.feihao.zhou.mapper.CourseMapper.selectAllCourseByStudentId")
            )
    })
    List<Student_Course> selectAllStudent();
}
